<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    width="600px"
    append-to-body
  >
    <div class="receipt-check-table">
      <table>
        <thead>
          <tr>
            <th>检查项目</th>
            <th>合格</th>
            <th>不合格</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>洁净无污染</td>
            <td><el-radio v-model="checkResult.clean" :label="true">是</el-radio></td>
            <td><el-radio v-model="checkResult.clean" :label="false">否</el-radio></td>
          </tr>
          <tr>
            <td>包装完好无缺</td>
            <td><el-radio v-model="checkResult.package" :label="true">是</el-radio></td>
            <td><el-radio v-model="checkResult.package" :label="false">否</el-radio></td>
          </tr>
          <tr>
            <td>运输条件符合要求</td>
            <td><el-radio v-model="checkResult.transport" :label="true">是</el-radio></td>
            <td><el-radio v-model="checkResult.transport" :label="false">否</el-radio></td>
          </tr>
        </tbody>
      </table>
      <div class="check-info">
        <p>检查人/日期: <el-input v-model="checkInfo.inspector" placeholder="请输入检查人及日期"></el-input></p>
        <p>不合格数量 : <el-input v-model="checkInfo.unqualifiedQty" placeholder="请输入数量"></el-input></p>
        <p>退回供应商日期: <el-input v-model="checkInfo.returnDate" placeholder="请选择日期"></el-input></p>
        <p>转入待检区数量: <el-input v-model="checkInfo.toBeInspectedQty" placeholder="请输入数量"></el-input></p>
      </div>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleConfirm">确认检查</el-button>
      <el-button @click="visible = false">取消</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: 'ReceiptCheckDialog',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '收货检查'
    }
  },
  data() {
    return {
      checkResult: {
        clean: null,
        package: null,
        transport: null
      },
      checkInfo: {
        inspector: '',
        unqualifiedQty: '',
        returnDate: '',
        toBeInspectedQty: ''
      }
    };
  },
  methods: {
    handleConfirm() {
      // 简单校验，确保三个检查项都选了“是”（合格）
      const isAllPass = Object.values(this.checkResult).every(item => item === true);
      if (isAllPass) {
        // 校验通过，向父组件传递检查结果
        this.$emit('checkPass', {
          checkResult: this.checkResult,
          checkInfo: this.checkInfo
        });
        this.visible = false;
      } else {
        this.$message.warning('请确保所有检查项目都合格后再确认');
      }
    }
  }
};
</script>

<style scoped>
.receipt-check-table table {
  width: 100%;
  border-collapse: collapse;
}
.receipt-check-table th,
.receipt-check-table td {
  border: 1px solid #ccc;
  padding: 8px;
  text-align: center;
}
.check-info p {
  margin: 10px 0;
}
</style>